﻿<template>
  <div>

    <el-row style="padding:0 35px 0 35px;">
      <query-table ref="index_query_table" :columns="tableColumns"
                   :default-query-params="queryCondition"
                   :query-fields="queryFields"
                   data-url="/project_compute_version/query"
                   data-request-method="post"
                   :row-style="getBackColor"
                   show-index></query-table>
    </el-row>
  </div>


</template>

<script>
  const MIN_NUMBER = 0;
  const MAX_NUMBER = 100000;
  export default {
    name: "EvaluationList",
    data() {
      return {
        isLoading: false,
        queryCondition: {
          projectName: '',
          modelId: '',
          projectType: '',
          projectStage: '',
          poolType: '',
          grade: '',
          locationType: '',
          buildOffice: '',
          state: 'audit,complete',
          type:'report,final',
          year: '',
          // minIrr:'',
          // maxIrr:'',
          // minPbp:'',
          // maxPbp:''
        },

        irrQuery: {
          irrBg: '',
          irrEd: '',
        },
        unitTypeMap: {},
        computeHistory: [],
        viewData: {
          show: false
        },
        exportPreviewData: {},
        projectState: [],
        projectStateMap: {},

        projectGradeList: [],
        userList: [],

        projectTypeMap: {},
        poolTypeMap: {},
        locationTypeMap: {},
        projectGradeMap: {},
        userMap: {},

        tableColumns:[
          {id:'name',name:'项目名称',align:'left'},
          {id:'buildOffice',name:'建设单位',align:'left',width:100,type:'office'},
          // {id:'invest',name:'建设投资',width:70},
          {id:'projectType',name:'项目类型',align:'left',width:100,type:'meta',source:'project-type'},
          // {id:'grade',name:'项目级别',type:'meta',source:'project-grade',width: 80},
          {id:'period',name:'评估期',width: 120,formatter:(val,row)=>{
            return row.calculateYearStart+'年-'+row.calculateYearEnd+'年';
            }},
          {id:'buildOffice',name:'内部收益率(%)',width:120,children: [
              {id:'irrBeforeTax',name:'税前',width:60,formatter:this.numberFormatter},
              {id:'irrAfterTax',name:'税后',width:60,formatter:this.numberFormatter},
            ]},
          {id:'buildOffice',name:'投资回收期(年)',width:120,children: [
              {id:'pbpBeforeTax',name:'税前',width:60,formatter:this.numberFormatter},
              {id:'pbpAfterTax',name:'税后',width:60,formatter:this.numberFormatter},
            ]},
          {id:'buildOffice',name:'财务净现值(万元)',width:120,children: [
              {id:'npvBeforeTax',name:'税前',width:60,formatter:this.numberFormatter},
              {id:'npvAfterTax',name:'税后',width:60,formatter:this.numberFormatter},
            ]},
          {id:'reportTime',name:'上报时间',width: 160},
          {id:'state',name:'状态',width: 70,type:'meta',source:'project-state',component:{id:'tag',getType:(val)=>{
            if(val=='complete') {
              return 'success';
            }
              }}},
          // {id:'rank',name:'排名',type:'index'},
          {id:'buildOffice',name:'操作',type:'button',width:70,children:[
              {text: '审核',permission:'evaluation:audit',type:'primary',click:(row)=>{
                if(row.mark=='subtract') {
                  this.openPage('/evaluation/compute-subtract',row.projectId,{version:row.id})
                } else {
                  this.openPage('/evaluation/compute-invoke',row.projectId,{version:row.id})
                }

                },isHide:(row)=>{return row.state!='audit';}
                },
              {text:'详情',click:(row)=>{
                  this.openPage('/evaluation/compute-invoke',row.projectId,{version:row.id})
                },isHide:(row)=>{return row.state=='audit'||!this.checkPermission('evaluation:audit');}}
            ]},
        ],
        queryFields:[
          {id:'name',name:'项目名称',colSpan:6},
          {id:'buildOffice',name:'建设单位',component:'company-select',colSpan:6,
            getDefaultValue:()=>{
              if(this.$route.query.buildOffice){
                return this.$route.query.buildOffice;
              }
              return '';
            }
          },
          {id:'projectType',name:'项目类型',component:'meta-select',type:'project-type',colSpan:6},
          {id:'grade',name:'项目级别',component: 'meta-select',type:'project-grade',colSpan:6,
            getDefaultValue:()=>{
              if(this.$route.query.grade){
                return this.$route.query.grade;
              }
              return '';
            }
          },
          {id:'state',name:'审核状态',component: 'meta-select',type:'project-state',colSpan:6,
            getDefaultValue:()=>{
              if(this.$route.query.state){
                return this.$route.query.state;
              }
              return '';
            }
          },
          {id:'year',name:'年度',component: 'year-picker',colSpan:6},
          {id:'irrRange',name:'内部收益率',component: 'input-number-range',colSpan:6,
            getDefaultValue:()=>{
              if(this.$route.query.irrRange){
                return this.$route.query.irrRange;
              }
              return [];
            }
          },
          {id:'pbpRange',name:'投资回收期',component: 'input-number-range',colSpan:6,
            getDefaultValue:()=>{
              if(this.$route.query.pbpRange){
                return this.$route.query.pbpRange;
              }
              return [];
            }
          },
          {id:'npvRange',name:'财务净现值',component: 'input-number-range',colSpan:6,
            getDefaultValue:()=>{
              if(this.$route.query.npvRange){
                return this.$route.query.npvRange;
              }
              return [];
            }
          },
        ],
      }
    },

    created: function () {
      if (this.$route.query.year) {
        this.queryCondition.year = this.$route.query.year+'';
      }

      if (this.$route.query.state) {
        this.projectState = this.$route.query.state.split(',');
      }

      if (this.$route.query.poolType) {
        this.queryCondition.poolType = this.$route.query.poolType;
      }

      if (this.$route.query.id) {
        this.queryCondition.markId = this.$route.query.id;
      }

      this.loadMetaNameMap('unit-type',map => {
        this.unitTypeMap = map;
      })
    },
    methods: {

      isNumber(val) {
        if (!val) {
          return true;
        }
        var regPos = /^\d+(\.\d+)?$/
        var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/
        if (regPos.test(val) || regNeg.test(val)) {
          return true
        } else {
          return false
        }
      },

      //数字格式化
      numberFormatter(val) {
        return val.toFixed(2);
      },
      getBackColor({row,rowIndex}) {
        if (row.id === this.queryCondition.markId) {
          return {
            "background": "rgb(213,252,192)"
          }
        }
      }

    },

  }
</script>